<?
require_once($_SERVER["DOCUMENT_ROOT"] . '/db/db.php');
$file = 'route.csv';
$where = "";
// Opens a connection to a db server.
$db = new DBConnection('dbname=assclap_realty port=5432 user=assclap_assclap password=fibo1235');
$whereArr = $_GET["data"];
foreach($whereArr as $thing)
{
	$where .= " id = $thing OR";	
}
$where = substr($where, 0, strlen($where) - 2);
$sql = "SELECT *, x(the_geom) as lon, y(the_geom) as lat FROM property WHERE $where ";
$Query = $db->CreateQuery($sql);

// Creates the Document.
$csv = array('Address, City, State, Zip, Name, Longitude, Latitude');

// Iterates through the results, creating one Placemark for each row.
while ($row = $Query->FetchRow())
{
	// Creates a Placemark and append it to the Document.
	$csv[] = '"' . $row['address'] . '", ' 
	. '"' . $row['city'] . '", '
	. '"' . $row['state'] . '", '
	. '"' . $row['zip'] . '", '
	. '"' . $row['price'] . '", '
	. $row['lon'] . ', '
	. $row['lat'];
}

$csvOutput = join("\n", $csv);
header('Content-type: application/csv');
header('Content-disposition: attachment; filename='. $file);
echo $csvOutput;
?>

